﻿using System;
using MODI;

namespace ImageOCR
{
    /// <summary>
    /// OCR识别类
    /// </summary>
    class OCR
    {
        public static bool ImageToOCR(string path, ref string value)
        {
            bool flag = true;
            var modiDocument = new Document();
            try
            {
                modiDocument.Create(path);

                modiDocument.OCR(MiLANGUAGES.miLANG_CHINESE_SIMPLIFIED, false, false);
                var mage = modiDocument.Images[0] as Image;
                if (mage != null)
                    value = mage.Layout.Text;
                modiDocument.Save();
            }
            catch(Exception e)
            {
                flag = false;
                LogService.Error("OCR程序异常",e);
            }
            finally
            {
                modiDocument.Close();
            }

            return flag;
        }
    }
}
